<template lang="">
    <div>
        <myheader/>
        <h2>用户中心</h2> 
        {{user.username}}<br>
        手机号{{user.mobile}}<br>
        上传头像：<van-uploader :after-read="upload" />
    </div>
</template>
<script>
import myheader from '@/components/myheader'
export default {
    data(){
        return{
            user:{},
            userid:localStorage.getItem('userid'),
        }
    },
    methods: {
        // 获取用户
        getUserinfo(){
            this.axios.get('users/getuserinfo?userid='+this.userid).then(res=>{
                this.user = res.data.user
            })
        },
        // 单文件上传
        upload(file){
            //此时可以自行将文件上传至服务器
            console.log(file);
            let data =new FormData()
            data.append('file',file.file)
            this.axios.post('users/upload',data)
            .then(res=>{
                //更新展示图片的地址

            })
        }
    },

    mounted() {
        this.getUserinfo()
    },
    components:{
        'myheader':myheader
    }
}
</script>
<style lang="">
    
</style>